import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import components from 'unplugin-vue-components/vite'
import autoImport from 'unplugin-auto-import/vite'
import { VarletUIResolver } from 'unplugin-vue-components/resolvers'
import { defineConfig } from 'vite'
function pathResolve (dir) {
  return resolve(__dirname, './', dir)
}
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    components({
      resolvers: [VarletUIResolver()]
    }),
    autoImport({
      resolvers: [VarletUIResolver({ autoImport: true })]
    }),
  ],
  resolve:{
    alias:{
      "@":pathResolve('src')
    }
  },
  base: process.env.NODE_ENV === 'production' ? './' : '/',
  server: {
    proxy: {
      '/api': {//反向代理的请求名,
        ws:true,
        target: "http://47.75.182.93:8080/jeesite/f/liveclass",//此处写后端地址
        changeOrigin: true,//默认是false,当为true时可以将当前ip改为目标url，故启用该功能
        rewrite: path => path.replace(/^\/api/,'')//重写url，注意一定要和请求名一致
      }
    }
  }
})
